package com.example.gfsquadwebviewproject.dialog;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import com.example.gfsquadwebviewproject.input.OnInputNumberCodeCallback;
import com.example.gfsquadwebviewproject.util.L;

/**
 * Created by Administrator on 2016/10/24.
 */
public class DialogBuilder {
    String TAG = "DialogBuilder";

    /*弹出的列表对话框
     */
    MyDialog mydialog = null ;
    WindowManager.LayoutParams lp;
    Window dialogWindow = null;

    public DialogBuilder(final Context context , OnInputNumberCodeCallback mCallback){
        try {
            if (mydialog != null) {
                mydialog = null;
            }
            mydialog = new MyDialog(context, mCallback);//对话框

            if (dialogWindow == null) {
                dialogWindow = mydialog.getWindow();
                DisplayMetrics dm2 = context.getResources().getDisplayMetrics();
                int width = dm2.widthPixels;
                int height = dm2.heightPixels;
                lp = dialogWindow.getAttributes();
                dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
                lp.width = (int)(width*0.26); // 宽度
                lp.height = (int)(height*0.70); // 高度
                lp.x = (width-lp.width)/2; // 新位置X坐标
                lp.y = (height-lp.height)/2; // 新位置Y坐标
                lp.alpha = 1.0f; // 透明度
                dialogWindow.setAttributes(lp);
            }
        }
        catch (Exception e){
            L.d(TAG,"DialogBuilder error:"+e);
        }

    }

    public void show(){
        mydialog.show();//显示对话框
    }

    public void dismiss(){
        mydialog.clearnNumber();
        mydialog.dismiss();
    }

    public void clearnPassword(){
        mydialog.clearnNumber();
    }

    public void setTv_hint_error_password(boolean show){
        mydialog.setTv_hint_error_password(show);
    }

}
